package com.test.reggie.model.address;

import com.test.reggie.base.BaseObserver;
import com.test.reggie.base.BasePresenter;
import com.test.reggie.bean.AddAddressBean;
import com.test.reggie.bean.AddressBookDetailsBean;
import com.test.reggie.bean.StringBean;

import java.util.Map;

public class AddAddressPrensenter extends BasePresenter<AddAddressView> {
    public AddAddressPrensenter(AddAddressView baseView) {
        super(baseView);
    }

    /**
     * 新增地址
     *
     * @param map
     */
    public void addAddress(Map<String, Object> map) {
        addDisposable(apiServer.addAddress(map), new BaseObserver<AddAddressBean>() {
            @Override
            public void onSuccess(AddAddressBean bean) {
                baseView.addAddressSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 根据id查询地址
     *
     * @param id
     */
    public void addressBookDetails(String id) {
        addDisposable(apiServer.addressBookDetails(id), new BaseObserver<AddressBookDetailsBean>() {
            @Override
            public void onSuccess(AddressBookDetailsBean bean) {
                baseView.addressBookDetailsSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 修改地址
     *
     * @param map
     */
    public void updateAddressBook(Map<String, Object> map) {
        addDisposable(apiServer.updateAddressBook(map), new BaseObserver<StringBean>() {
            @Override
            public void onSuccess(StringBean bean) {
                baseView.updateAddressBookSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }
}
